#include "zf_common_headfile.h"
//*******************/
//UDF˵��: User Defined Function
//@author �ֹ��� 2021.11.23
//*******************/
extern uint8 shuju;
static bool IsGyroOffsetReset = true;          /////�����Ҫ������������Ʈ�����򽫸ı�����Ϊ   true
uint8 ErrLoop = 0;
uint8 LCDflag = 0;


void User_Init (void)
{
    Key_Init();
    if(KEY_S6==1)
    {
        tft180_init();
        LCDflag = 1;
    }
    else if(KEY_S6==0)
    {
        oled_init();
        LCDflag = 0;
    }
    oled_show_chinese(15, 2, 16, grznc, 6);
    ad_init();


    oled_show_string(0, 5, "KEY ok");
    ad_voltage(); //读取电池电压
    /***********显示电池电压ʾ**************/
    oled_show_string(0, 0, "BAT:");

    oled_show_float(24, 0, voltage, 5, 2);

    oled_show_string(55, 0, "V");

//    if(voltage<7.7&&voltage>3)
//    Bee_on();
    /********************************/
    Servo_Init();
    Speed_Init();
    oled_show_string(0, 5, "SPE ok");

//   oled_show_int(24, 0,shuju, 3);
//
//    while (BMX055_init() == false)  //�����ǳ�ʼ��
//    {
//
//        ErrLoop++;
//        if (ErrLoop == 5){
////            Bee_on();                         //////�������5��ʧ����ֱ������
////            break;
//        }
////        else
////            Bee_off();
//            ErrLoop = 0;
//    }

//    while(imu660ra_init())
//    {
//        oled_show_string(0, 7,"NO_INT_ICM20602");
//        Bee_on();
//    }
//        while(icm20602_init())
//        {
//            oled_show_string(0, 7,"NO_INT_ICM20602");
//            Bee_on();
//        }
//    MPU6050_Mahony_Init(2);

    oled_show_string(0, 5, "BMX ok");

//    Encoder_Init();

//	ad_init();//��ų�ʼ��

//    while(1);
//    dl1a_init();

//    zLpidint();


    Bee_off();


//    if (IsGyroOffsetReset == true)
//    {
//        GyroOffset_init(IMU660RA_DataRead,(float*)&imu660ra_gyro_x,(float*)&imu660ra_gyro_y,(float*)&imu660ra_gyro_z);
//        system_delay_ms(1000);
//        oled_show_string(0, 5, "BMX ok");
//    }
    //1ms�ж�
    //    //100us�ж�
//    pit_ms_init(CCU60_CH1, 1);
//        pit_enable(CCU60_CH1);
    oled_show_string(0, 5, "ALL ok");
    User_StartMenu(); //������ʼ��
//    speed_test();//电机测试函数
//    Servo_Max_Angle();//舵机测试函数
    while(mt9v03x_init())
    {
        oled_show_string(0, 7,"ffffffffff");
        Bee_on();
    }
    oled_show_string(0, 5, "OKKKKKKKKKKK");
//    while(abs(Att_Angle.rol-87)>5)
//    {
//        //����10һֱѭ��
//        oled_show_int(0, 0, Att_Angle.rol,5);
//        oled_show_int(3, 0, Att_Angle.rol-87,5);
//    }

//   system_delay_ms(1000);
//   system_delay_ms(1000);
//   system_delay_ms(1000);
//   system_delay_ms(1000);
//   system_delay_ms(1000);
//   system_delay_ms(1000);
//    Encoder_ValInit();//�������
    oled_clear();
//    pit_ms_init(CCU60_CH0, 4);
//        pit_enable(CCU60_CH0);


//            pit_interrupt_ms(CCU6_0, PIT_CH0, 4); //2ms�ж�                                                                       // ��ʼ��CCU6_0ģ���PIT_CH0ͨ���� Ƶ��500Hz 2ms
//            pit_enable_interrupt(CCU6_0, PIT_CH0);
//    Bee_on();
    /************************�жϳ�ʼ��********************************/
    pit_init(CCU60_CH0, 4000);
        pit_enable(CCU60_CH0);
}

const uint8 grznc[]= {
0x00,0x00,0xF8,0x08,0x08,0x08,0x08,0x09,0x0E,0x08,0x08,0x08,0x08,0x08,0x00,0x00,
0x80,0x60,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"��",0
0x08,0xC8,0xB8,0x8F,0xE8,0x88,0x88,0x40,0x30,0x0F,0xC8,0x08,0x28,0x18,0x00,0x00,
0x08,0x18,0x08,0x08,0xFF,0x04,0x84,0x40,0x30,0x0E,0x01,0x0E,0x30,0x40,0x80,0x00,//"��",1
0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,
0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00,//"��",2
0x80,0x82,0x82,0x82,0x82,0x82,0x82,0xE2,0xA2,0x92,0x8A,0x86,0x82,0x80,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"��",3
0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,//"��",4
0x00,0xFE,0x02,0x22,0xDA,0x06,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xFF,0x08,0x10,0x88,0x47,0x20,0x18,0x07,0x00,0x07,0x18,0x20,0x40,0x80,0x00,//"��",5
};
